package com.meilingcloud.biobank.controller;

import com.meilingcloud.biobank.domain.SampleAlarm;
import com.meilingcloud.biobank.service.ISampleAlarmService;
import com.meilingcloud.common.core.controller.BaseController;
import com.meilingcloud.common.core.domain.AjaxResult;
import com.meilingcloud.common.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 样本预警 Controller
 *
 * @author chenl
 * @date 2021-05-26
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/biobank/sampleAlarm")
public class SampleAlarmController extends BaseController {

    private final ISampleAlarmService iSampleAlarmService;

    /**
     * 查询样本预警 列表
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleAlarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SampleAlarm sampleAlarm) {
        startPage();
        List<SampleAlarm> list = iSampleAlarmService.queryList(sampleAlarm);
        iSampleAlarmService.handleResults(list);
        return getDataTable(list);
    }

    /**
     * 获取样本预警数量
     */
    @GetMapping(value = "/getAlarmCount")
    public AjaxResult getAlarmCount() {
        return AjaxResult.success(iSampleAlarmService.getAlarmCount());
    }

    /**
     * 获取样本预警 详细信息
     */
    @PreAuthorize("@ss.hasPermi('biobank:sampleAlarm:query')")
    @GetMapping(value = "/{sampAlarmId}")
    public AjaxResult getInfo(@PathVariable("sampAlarmId") Long sampAlarmId) {
        return AjaxResult.success(iSampleAlarmService.getById(sampAlarmId));
    }

}
